<%--
  Created by IntelliJ IDEA.
  User: 10452
  Date: 2022/3/22
  Time: 1:01
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
    <title></title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap-responsive.css" />
    <link rel="stylesheet" type="text/css" href="../Css/style.css" />
    <script type="text/javascript" src="../Js/jquery.js"></script>
    <script type="text/javascript" src="../Js/jquery.sorted.js"></script>
    <script type="text/javascript" src="../Js/bootstrap.js"></script>
    <script type="text/javascript" src="../Js/ckform.js"></script>
    <script type="text/javascript" src="../Js/common.js"></script>
    <style type="text/css">
        body {
            padding-bottom: 40px;
        }
        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }


    </style>
    <script type="text/javascript">
        $(function () {
            loadData();
            $("div[id='spanclick']>span").click(function() {
                if (($(this).attr("class")) == 'disabled')
                    return;
                let num = $(this).attr("name");
                $("span[id='pageNum']").text(num)
                loadData();
            });
        });
        function loadData(){
            let pageNum = $('#pageNum').text()
            let ResourceName = $('#ResourceName').val();
            $.ajax({
                type: "GET",
                url: "/resource/menuList",
                data: "pageNum="+pageNum+"&ResourceName="+ResourceName+"",
                dataType: "json",
                success: function(vo){
                    let list=vo.pageInfo.list;
                    let str="";
                    for (let i = 0; i < list.length; i++) {
                        let m_name = list[i].m_name
                        let m_url = list[i].m_url
                        let m_state = list[i].m_state==0?"有效":"无效"
                        let m_id = list[i].m_id;

                        str+='<tr>' +
                            '            <td style="vertical-align:middle;"><input type="checkbox" name="check" value="1"></td>' +
                            '            <td>'+m_name+'</td>' +
                            '            <td>'+m_url+'</td>' +
                            '            <td>'+m_state+'</td>' +
                            '            <td><a href="/resource/edit/'+m_id+'">编辑</a>&nbsp;&nbsp;&nbsp;<a href="javascript:alert('+'删除成功'+')">删除</a>'+'</td>' +

                            '</tr>'
                    }
                    fillPageDate(vo.pageInfo);
                    $("#MenuInfo").html(str)
                }
            });
            $('#newNav').click(function(){
                window.location.href="add.html";
            });
        }


        function checkall(){
            var alls=document.getElementsByName("check");
            var ch=document.getElementById("checkall");
            if(ch.checked){
                for(var i=0;i<alls.length;i++){
                    alls[i].checked=true;
                }
            }else{
                for(var i=0;i<alls.length;i++){
                    alls[i].checked=false;
                }
            }
        }
        function delAll(){
            var alls=document.getElementsByName("check");
            var ids=new Array();
            for(var i=0;i<alls.length;i++){
                if(alls[i].checked){
                    ids.push(alls[i].value);
                }
            }
            if(ids.length>0){
                if(confirm("确认删除?")){
                    alert("删除成功!");
                }
            }else{
                alert("请选中要删除的项");
            }
        }
        function fillPageDate(pageInfo){
            //填充信息
            $("#total").html(pageInfo.total);
            $("#pages").html(pageInfo.pages);
            $("#pageNum").html(pageInfo.pageNum);
            //设置按钮的属性值和样式
            $("#firstPage").attr("name",1);
            $("#prePage").attr("name",pageInfo.prePage);
            $("#nextPage").attr("name",pageInfo.nextPage);
            $("#lastPage").attr("name",pageInfo.pages);
            $("#firstPage").removeClass("disabled");
            $("#prePage").removeClass("disabled");
            $("#nextPage").removeClass("disabled");
            $("#lastPage").removeClass("disabled");
            if(pageInfo.isFirstPage){//如果是第一页：上一页和首页禁用
                $("#firstPage").addClass("disabled");
                $("#prePage").addClass("disabled");
            }
            if(pageInfo.isLastPage){//如果已经是最后一页：下一页和末页禁用
                $("#nextPage").addClass("disabled");
                $("#lastPage").addClass("disabled");
            }
        }
    </script>
</head>
<body>
<form class="form-inline definewidth m20" action="index.html" method="get" id="form1">
    资源(菜单)名称：
    <input type="text" name="ResourceName" id="ResourceName"class="abc input-default" placeholder="" value="">&nbsp;&nbsp;
    <button type="button" class="btn btn-primary" onclick=loadData()>查询</button>
</form>
<table class="table table-bordered table-hover definewidth m10" id="tableInfo">
    <thead>
    <tr>
        <th width="5%"><input type="checkbox" id="checkall" onChange="checkall();"></th>
        <th>资源名称</th>
        <th>路径Url</th>
        <th>是否有效</th>
        <th  width="10%">操作</th>
    </tr>
    </thead>
    <tbody id="MenuInfo">
<%--        <c:forEach items="${sessionScope.menus}" var="menu">
            <tr>
                <td style="vertical-align:middle;"><input type="checkbox" name="check" value="1"></td>
                <td>${menu.m_name}</td>
                <td>${menu.m_url}</td>
                <td>
                        ${menu.m_state==0?"有效":"无效"}
                </td>
                <td>
                    <a href="edit.html">编辑</a>&nbsp;&nbsp;&nbsp;<a href="javascript:alert('删除成功！');">删除</a>
                </td>
            </tr>
        </c:forEach>--%>
    </tbody>
</table>
<table class="table table-bordered table-hover definewidth m10" >
    <tr><th colspan="5">
        <div class="inline pull-right page">
            <span id="total">total</span>条记录
            <span id="pageNum">1</span>/<span id="pages">pages</span>页
            <div id="spanclick">
                <span name="pageValue" id="firstPage"><a href="javascript:void(0)">首页</a></span>
                <span name="pageValue" id="prePage"><a href='javascript:void(0)'>上一页</a></span>
                <span name="pageValue" id="nextPage"><a href='javascript:void(0)'>下一页</a></span>
                <span name="pageValue" id="lastPage"><a href='javascript:void(0)'>尾页</a></span>
            </div>
        </div>
        <div>
            <button type="button" class="btn btn-success" id="newNav">添加资源</button>&nbsp;&nbsp;&nbsp;
            <button type="button" class="btn btn-success" id="delPro" onClick="delAll();">删除选中</button>
        </div>
    </th>
    </tr>
</table>
</body>
</html>
